﻿package strhelp {
	
	public class StringHelper {
		
		public function StringHelper() {
    	}

    	

    	public function trim(str:String, char:String=' '):String {
        	return trimBack(trimFront(str, char), char);
    	}

    	public function trimFront(str:String, char:String):String {
        	char = stringToCharacter(char);
        	if (str.charAt(0) == char) {
            	str = trimFront(str.substring(1), char);
        	}
        	return str;
    	}

    	public function trimBack(str:String, char:String):String {
        	char = stringToCharacter(char);
        	if (str.charAt(str.length - 1) == char) {
            	str = trimBack(str.substring(0, str.length - 1), char);
        	}
			str = str.replace("\n\r",'');
			str = str.replace("\r\n",'');
			str = str.replace("\r",'');
			str = str.replace("\n",'');
        	return str;
    	}

    	public function stringToCharacter(str:String):String {
        	if (str.length == 1) {
            	return str;
        	}
        	return str.slice(0, 1);
   		}
	}
	
}
